home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2001 May / SGI IRIX Base Documentation 2001 May.iso / usr / relnotes / c++_eoe / ch4.z / ch4
Text File  |  2001-04-17  |  16KB  |  593 lines

  1.  
  2.  
  3.  
  4.                                      - 1 -
  5.  
  6.  
  7.  
  8.           7.3.1.1m C++ Compiler Execution Environment Release Notes
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.                                      - 2 -
  66.  
  67.  
  68.  
  69.           4.  _N_e_w__F_e_a_t_u_r_e_s
  70.  
  71.           This chapter lists the new C++ features for the MIPSpro 7.3
  72.           release.
  73.  
  74.  
  75.  
  76.           4.1  _T_e_m_p_l_a_t_e_-_R_e_l_a_t_e_d__f_e_a_t_u_r_e_s
  77.  
  78.           New C++ template-related features are described in the
  79.           following sections.
  80.  
  81.  
  82.           4.1.1  _O_v_e_r_l_o_a_d_e_d__F_u_n_c_t_i_o_n__T_e_m_p_l_a_t_e_s
  83.  
  84.           The 2.38 front end now permits you to overload a function
  85.           template, as in the following example.
  86.  
  87.           template <class T> void f(T t);           (1)
  88.           template <class X> void f(X p*);          (2)
  89.  
  90.           When you call an overloaded function template, the compiler
  91.           selects the most specific version that matches the argument.
  92.           If the function f is overloaded as in the previous example,
  93.           the compiler selects version (1) when you write f(10) and it
  94.           selects version (2) when you write f((double*) 0). (Previous
  95.           versions of the compiler would issue an error in this case.)
  96.  
  97.           The C++ standard refers to this feature as "partial ordering
  98.           of function templates."  It is sometimes also called
  99.           "partial specialization of functions."
  100.  
  101.  
  102.           4.1.2  _E_x_p_l_i_c_i_t__S_p_e_c_i_f_i_c_a_t_i_o_n__o_f__F_u_n_c_t_i_o_n__T_e_m_p_l_a_t_e__A_r_g_u_m_e_n_t_s
  103.  
  104.            The usual way of calling a function template is the same as
  105.           calling an ordinary function.  If you write f(10), for
  106.           example, the compiler deduces the types of the template
  107.           parameters.  It is now also possible to specify the template
  108.           arguments explicitly, as in f<int>(10).
  109.  
  110.           This feature makes it possible to write function templates
  111.           whose template arguments cannot be deduced.  For example:
  112.  
  113.           template <class T>
  114.           inline T* null_pointer() { return (T*) 0; }
  115.  
  116.           It is impossible for the compiler to deduce the type of the
  117.           template argument of null_pointer from the function's
  118.           arguments because the function takes no arguments.  You must
  119.           explicitly provide the template arguments when you call this
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.                                      - 3 -
  132.  
  133.  
  134.  
  135.           function, as in the following example:
  136.  
  137.           null_pointer<X>().
  138.  
  139.           Previous versions of the compiler did not permit function
  140.           templates with template arguments that could not be deduced.
  141.  
  142.  
  143.           4.1.3  _U_n_n_a_m_e_d__T_e_m_p_l_a_t_e__P_a_r_a_m_e_t_e_r_s
  144.  
  145.           Unnamed template parameters are now legal, as in the
  146.           following example:
  147.  
  148.           template <class,int> struct A {};
  149.           A<char,1> a1;
  150.  
  151.  
  152.           4.1.4  _N_e_w__S_y_n_t_a_x__f_o_r__R_e_f_e_r_r_i_n_g__t_o__T_e_m_p_l_a_t_e__M_e_m_b_e_r_s
  153.  
  154.           The C++ standard allows (and in some cases requires) a new
  155.           syntax for referring to a member template of a class.  If a
  156.           class A has a member template B<T>, you can write
  157.           A::template B<T>, or a.template B<T>, or pa->template B<T>.
  158.  
  159.           Example:
  160.  
  161.           struct X {
  162.             template <class T> struct Y;
  163.             template <class T> void f();
  164.             template <class T> void g(T);
  165.           };
  166.  
  167.           X x;
  168.           X::template Y<int> y;
  169.           x.template f<int>();
  170.           x.g(10);           // No "template" keyword here, because we are
  171.                              // not providing g's template argument list.
  172.  
  173.  
  174.           In this example, the new syntax is not required.  It is
  175.           required in only one specific case: when you are referring
  176.           to a member template of a class that itself depends on a
  177.           template parameter.
  178.  
  179.           Example:
  180.  
  181.           template <class T>
  182.           void f(T t) {
  183.             T::template Y<int> y;
  184.             ...
  185.           }
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.                                      - 4 -
  198.  
  199.  
  200.  
  201.           The new syntax is required in this case because the compiler
  202.           must be able to interpret "<" as the beginning of a template
  203.           argument list or as a less-than operator.
  204.  
  205.           (Previous releases of the compiler neither required nor
  206.           allowed the new syntax.  This release allows it but does not
  207.           require it.  Future releases might require it.)
  208.  
  209.  
  210.  
  211.           4.2  _N_e_w__C_o_m_p_i_l_e_r__C_o_m_m_a_n_d__L_i_n_e__O_p_t_i_o_n_s
  212.  
  213.           The following sections describe new compiler options for
  214.           C++.
  215.  
  216.  
  217.           4.2.1  _I_n_t_e_r_p_r_o_c_e_d_u_r_a_l__P_a_r_a_l_l_e_l_i_z_a_t_i_o_n
  218.  
  219.           The -ipa option invokes the Interprocedural Analyzer option
  220.           group. This is a new alias for -IPA:=ON.  Compiling with the
  221.           -ipa and -pfa options together instructs the compiler to
  222.           perform interprocedural parallelization.  The compiler
  223.           applies a sophisticated analysis to determine when it can
  224.           parallelize loops with calls.
  225.  
  226.  
  227.           4.2.2  _L_i_s_t_i_n_g__C_o_n_t_r_o_l
  228.  
  229.           The -clist option invokes the listing control group.  This
  230.           is equivalent to -CLIST:=ON.
  231.  
  232.           The emit_omp=_f_l_a_g suboption to the -CLIST option directs the
  233.           compiler to use OpenMP directives (_f_l_a_g=ON) or MIPS(TM)
  234.           multiprocessing directives (_f_l_a_g=OFF).
  235.  
  236.  
  237.  
  238.           4.2.3  _M_e_m_o_r_y__L_o_c_a_t_i_o_n
  239.  
  240.           The speculative_ptr_deref={ON/OFF} suboption to the -OPT
  241.           compiler option allows speculative loads of memory locations
  242.           that differ by a small offset from some referenced memory
  243.           location.  For more information, see the opt(5) man page.
  244.  
  245.  
  246.           4.2.4  _P_a_r_a_l_l_e_l_i_z_a_t_i_o_n__A_n_a_l_y_s_i_s
  247.  
  248.           The -LNO:pure={_f_l_a_g} option tells the compiler how to use
  249.           the "no side effects" and "pure" pragmas when gathering
  250.           information about calls for parallelization analysis.
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.                                      - 5 -
  264.  
  265.  
  266.  
  267.           4.2.5  _T_a_r_g_e_t__O_p_t_i_o_n__G_r_o_u_p__C_o_n_t_r_o_l_s
  268.  
  269.           The target option group has the following new controls:
  270.  
  271.           dismiss_mem_faults=_f_l_a_g  Forces the kernel to dismiss memory
  272.                                    faults that occur during execution.
  273.  
  274.           exc_max=_v_a_l_u_e            Specifies the maximum set of IEEE-
  275.                                    754 floating point exceptions for
  276.                                    which traps can be enabled at run
  277.                                    time.
  278.  
  279.           exc_min=_v_a_l_u_e            Specifies the minimum set of IEEE-
  280.                                    754 floating point exceptions for
  281.                                    which traps must be enabled at run
  282.                                    time.
  283.  
  284.           isa=_v_a_l_u_e                Identifies the target instruction
  285.                                    set architecture for compilation.
  286.  
  287.           sync=_f_l_a_g                Enables or disables the use of SYNC
  288.                                    instructions.
  289.  
  290.  
  291.           4.2.6  _-_T_E_N_V__S_u_b_o_p_t_i_o_n
  292.  
  293.           The large_got=ON/OFF suboption to the -TENV compiler option
  294.           replaces the -avoid_gp_overflow and the -xgot options.
  295.  
  296.  
  297.  
  298.           4.3  _O_t_h_e_r__N_e_w__F_e_a_t_u_r_e_s
  299.  
  300.           The following sections describe other new C++ features.
  301.  
  302.  
  303.           4.3.1  _C_-_C_a_l_l_a_b_l_e__R_o_u_t_i_n_e_s
  304.  
  305.           C-callable versions of POPCNT, POPPAR, LEADZ, and MASK are
  306.           now available.
  307.  
  308.  
  309.           4.3.2  _C_o_v_a_r_i_a_n_t__R_e_t_u_r_n__T_y_p_e_s
  310.  
  311.           Usually, when a derived class overrides a base class's
  312.           virtual member function, the function in the derived class
  313.           must have exactly the same signature as in the base class.
  314.           There is, however, one small exception.
  315.  
  316.           If a virtual function in a base class returns a pointer (or
  317.           reference) to a class X, the overriding virtual function can
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.                                      - 6 -
  330.  
  331.  
  332.  
  333.           return a pointer to X or to some other class that inherits
  334.           from X.
  335.  
  336.           Example:
  337.  
  338.           struct X {
  339.             virtual ~X() {}
  340.             virtual X* clone() const { return new X(*this); }
  341.           };
  342.  
  343.           struct Y : public X {
  344.             virtual Y* clone() const { return new Y(*this); }
  345.           };
  346.  
  347.           Previous compiler releases did not permit covariant return
  348.           types.  They required a virtual member function in a derived
  349.           class to have exactly the same return type as in the base
  350.           class.
  351.  
  352.  
  353.           4.3.3  _L_o_o_k_u_p _R_u_l_e_s _f_o_r _M_e_m_b_e_r _R_e_f_e_r_e_n_c_e_s _o_f _t_h_e _F_o_r_m _x._A::_B
  354.           _a_n_d _p->_A::_B
  355.  
  356.           In a class member access expression like x.A::i or p->A::i,
  357.           the class reference (in this case A) is looked up both in
  358.           the context of the expression and in the context of the left
  359.           operand of the "." or "->" operator (in this case, the class
  360.           of which x is a member).  Formerly, the class reference was
  361.           looked up only in the first context, as in the following
  362.           example:
  363.  
  364.           struct A {
  365.             typedef A B;
  366.             int i;
  367.           };
  368.  
  369.           int main() {
  370.             A a;
  371.             a.B:: i = 1; // not previously allowed
  372.           }
  373.  
  374.  
  375.  
  376.           4.3.4  _N_e_w__#_p_r_a_g_m_a
  377.  
  378.           The unknown_control_flow (_f_u_n_c_1 [, _f_u_n_c_2 ...]) #pragma
  379.           indicates that the procedures listed as _f_u_n_c_1 and _f_u_n_c_2,
  380.           etc. have a nonstandard control flow behavior.
  381.  
  382.  
  383.  
  384.  
  385.  
  386.  
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393.  
  394.  
  395.                                      - 7 -
  396.  
  397.  
  398.  
  399.           4.3.5  _O_p_e_n_M_P__D_i_r_e_c_t_i_v_e_s__f_o_r__S_h_a_r_e_d__M_e_m_o_r_y__M_u_l_t_i_p_r_o_c_e_s_s_i_n_g
  400.  
  401.           OpenMP directives are based on the OpenMP C/C++ application
  402.           programming interface (API) standard.  Programs that use
  403.           these directives are portable and can be compiled by other
  404.           compilers that support the OpenMP standard.
  405.  
  406.           To enable recognition of the OpenMP directives, specify -mp
  407.           on the cc or CC command line.  Details of these directives
  408.           are documented in the _M_I_P_S_p_r_o _C _a_n_d _C++ _P_r_a_g_m_a_s manual.
  409.  
  410.  
  411.  
  412.           4.3.6  _O_v_e_r_l_o_a_d_i_n_g__o_n__E_n_u_m_e_r_a_t_i_o_n_s
  413.  
  414.           You cannot overload an operator if all of its arguments are
  415.           built-in types, but you can overload it if at least one
  416.           argument is a class or enumeration type.
  417.  
  418.           Example:
  419.  
  420.           enum E {a, b, c, error};
  421.  
  422.           E operator++ (E e) {
  423.             switch(e) {
  424.             case a:
  425.               return b;
  426.             case b:
  427.               return c;
  428.             case c:
  429.               return a;
  430.             default:
  431.               return error;
  432.             }
  433.           }
  434.  
  435.           Previous compiler releases did not allow overloaded
  436.           operators all of whose arguments were enumeration types.
  437.  
  438.  
  439.  
  440.           4.3.7  _S_t_a_n_d_a_r_d__C_+_+__L_i_b_r_a_r_y
  441.  
  442.           A standard C++ library is now available.  This library
  443.           includes a standard-conforming I/O library, which has new
  444.           header names. For example, the old iostream.h header is now
  445.           iostream. The functionality for this feature is provided in
  446.           libCio.so, which is provided for n32- and 64-bit ABIs. Using
  447.           the new library requires including the -LANG:std option on
  448.           the command line.  The -LANG:std option also triggers the
  449.           following ISO/ANSI standard-conforming behavior:
  450.  
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.  
  460.  
  461.                                      - 8 -
  462.  
  463.  
  464.  
  465.              +o A user-defined assignment operator for class X is a
  466.                nonstatic nontemplate operator= with a single parameter
  467.                of one of the following types:
  468.  
  469.                X
  470.                X&
  471.                const X&
  472.                volatile X&
  473.                const volatile X&
  474.  
  475.                A template operator= or an operator= with a different
  476.                type (even if the type is derived from X) is not
  477.                considered to be an assignment operator, and does not
  478.                prevent the compiler from generating an implicit
  479.                operator=.
  480.  
  481.              +o The typename keyword cannot be omitted where the
  482.                standard mandates it.
  483.  
  484.              +o The scope of a variable declared in the initialization
  485.                of a for-loop is the for-loop and not the surrounding
  486.                scope.
  487.  
  488.              +o Guiding declarations are not allowed.
  489.  
  490.              +o Old-style template specializations are not allowed.
  491.                The new template syntax is now required for complete
  492.                specializations.
  493.  
  494.              +o When you use -LANG:std, there is no longer an implicit
  495.                conversion from function pointer types to void*.
  496.                However, it is still possible to do the conversion with
  497.                a cast.
  498.  
  499.              +o When you use -LANG:std, operator new throws a bad_alloc
  500.                exception to signal out of memory, rather than
  501.                returning a null pointer.
  502.  
  503.              +o The overload resolution rules are now stricter in the
  504.                sense that some old tie-breaker rules have been
  505.                abolished.  The effect of this is that some function
  506.                calls that were resolved by these discarded rules are
  507.                now ambiguous.  For example, consider the following
  508.                code:
  509.  
  510.                struct X {
  511.                  X(int);
  512.                };
  513.  
  514.                void f(int, const int *);
  515.                void f(X, int *);
  516.  
  517.  
  518.  
  519.  
  520.  
  521.  
  522.  
  523.  
  524.  
  525.  
  526.  
  527.                                      - 9 -
  528.  
  529.  
  530.  
  531.                int main()
  532.                {
  533.                  int *p;
  534.                  f(1, p);
  535.                }
  536.  
  537.                If -LANG:std is specified, the call to f(1, p) becomes
  538.                ambiguous.  Because f(int, const int*) is preferred for
  539.                the first argument but f(X, int *) is preferred for the
  540.                second, no attempt is made to reconsider and break the
  541.                tie.
  542.  
  543.              +o The _STANDARD_C_PLUS_PLUS macro is defined.
  544.  
  545.  
  546.  
  547.           4.3.8  _S_u_p_e_r_c_o_m_p_u_t_i_n_g__A_P_I__S_u_p_p_o_r_t
  548.  
  549.           The MIPSpro 7.3 release supports the Supercomputing
  550.           Application Programming Interface (API), a set of language
  551.           features and library functions that are implemented across
  552.           the Silicon Graphics and Cray(TM) product line to meet the
  553.           application portability needs of high-performance, technical
  554.           computing customers.  For more information, see the online
  555.           Supercomputing API document at the following URL:
  556.  
  557.           http://www.sgi.com/software/scapi.html
  558.  
  559.  
  560.  
  561.  
  562.  
  563.  
  564.  
  565.  
  566.  
  567.  
  568.  
  569.  
  570.  
  571.  
  572.  
  573.  
  574.  
  575.  
  576.  
  577.  
  578.  
  579.  
  580.  
  581.  
  582.  
  583.  
  584.  
  585.  
  586.  
  587.  
  588.  
  589.  
  590.